﻿@model IEnumerable<KRM.Core.tblLoad>

@{
    ViewBag.Title = "Book Load";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<script src="~/js/load.js"></script>
<script>
    $(document).ready(function () {
        //$("#tree").treeview({
        //    animated: "fast",
        //    collapsed: true,
        //});
        $("#tree li ul li div,#tree li div").click(function () {
            $(this).addClass("list-selected");
            $("#tree li ul li div").not(this).removeClass('list-selected');
            $("#tree li div").not(this).removeClass('list-selected');
        });
    });
</script>
<div class="container-fluid">
    <div class="page-header"></div>
    <div class="border-padding10">
        <div class="row-fluid">
            <div class="span6">
                <label>Loads to be booked in:   @Model.Count()</label>
            </div>
            <div class="span6">
                <a href="/load/bookload" class="btn btn-primary" style="float: right">Refresh</a>
            </div>
        </div>
    </div>
    
    <div class="row-fluid">
        <div class="span3">
            <div class="border-padding10"style="height: 480px;">
                 <ul id="tree" style="list-style-type: square;">
                        @{
                            var lstDate = Model.Select(p => (p.PlannedDeliveryDate??DateTime.Now).Date).Distinct();
                            foreach (var date in lstDate)
                            {
                                <li style="cursor: pointer" >
                                <div class=""> @date.ToShortDateString()</div>
                                </li>
                                <ul style="list-style-type: circle;">
                                @foreach (var load in Model.Where(p => (p.PlannedDeliveryDate ?? DateTime.Now).Date == date))
                                {
                                    <li onclick=" ViewBookLoadDetail(@load.LoadID);"style="cursor: pointer">
                                        <div>@load.LoadCode [@load.Postcode]</div>
                                    </li>
                                }
                                </ul>
                            }
                        }
                    </ul>
            </div>
        </div>
        <div class="span9">
            <div class="border-padding10"style="height: 480px;" id="divLoadDetails">
                @if(ViewBag.SelectedLoadId!=null)
                {
                    @Html.Action("BookLoadDetails",new{loadId=ViewBag.SelectedLoadId});
                }
            </div>
        </div>
    </div>
</div>